package com.example.huawei.system.controller;


import com.example.huawei.system.entity.UserCar;
import com.example.huawei.system.result.Result;
import com.example.huawei.system.service.UserCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "用户车辆信息接口")
@RestController
@RequestMapping("/userCar")
public class UserCarController {

    @Autowired
    private UserCarService userCarService;


//    @ApiOperation(value = "分页查询用户车辆信息", notes = "分页查询用户车辆信息")
//    @GetMapping("/page")
//    public Result queryPage(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
//                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
//        Page<UserCar> page = new Page<>(pageNo, pageSize);
//        return Result.ok(userCarService.page(page));
//    }

    @ApiOperation(value = "列表查询用户车辆信息", notes = "列表查询用户车辆信息")
    @GetMapping("/list")
    public Result<List<UserCar>> queryList(UserCar userCar) {
        return Result.ok(userCarService.queryList(userCar));
    }


    @ApiOperation(value = "新增用户车辆信息", notes = "新增用户车辆信息")
    @PostMapping("/add")
    public Result<?> add(@RequestBody UserCar userCar) {
        userCar.setCreateTime(new Date());
        boolean flag = userCarService.save(userCar);
        return flag ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "修改用户车辆信息", notes = "修改用户车辆信息")
    @PutMapping("/edit")
    public Result<?> edit(@RequestBody UserCar userCar) {
        boolean flag = userCarService.updateById(userCar);
        return flag ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "删除用户车辆信息", notes = "删除用户车辆信息")
    @DeleteMapping("/del/{id}")
    public Result<?> delete(@PathVariable("id") String id) {
        boolean flag = userCarService.removeById(id);
        return flag ? Result.ok() : Result.error();
    }
}
